//
//  YCStatusCell.swift
//  swift微博
//
//  Created by 姚伟聪 on 15/12/21.
//  Copyright © 2015年 姚伟聪. All rights reserved.
//

import UIKit

class YCStatusCell: UITableViewCell {
    
    //配图的约束
    var pictureViewWidthContans: NSLayoutConstraint?
    var pictureViewHeightContans: NSLayoutConstraint?
    
    var status:YCStatus?{
    
        didSet{
        
            headView.status = status
            
            contentLab.text = status?.text
            
            pictureView.status = status
            
            let picSize = pictureView.calculatePictureSize()
            
            pictureViewHeightContans?.constant = picSize.height
            pictureViewWidthContans?.constant = picSize.width
        }
    
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        addUI()
       
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func addUI(){
    
        
       contentView.addSubview(headView)
       contentView.addSubview(contentLab)
       contentView.addSubview(footView)
       contentView.addSubview(pictureView)
        
        headView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: contentView, size: CGSize(width: UIScreen.mainScreen().bounds.size.width, height: 44), offset: CGPointZero)
        
        contentLab.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: headView, size: nil, offset: CGPoint(x: 8, y: 8))
        contentView.addConstraint(NSLayoutConstraint(item: contentLab, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: UIScreen.mainScreen().bounds.width - 2 * 8))
        
        //获得约束
       let constranint = pictureView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: contentLab, size: CGSize(width: 290, height: 100), offset: CGPoint(x: 0, y: 10))
        pictureViewWidthContans = pictureView.ff_Constraint(constranint, attribute: NSLayoutAttribute.Width)
        pictureViewHeightContans = pictureView.ff_Constraint(constranint, attribute: NSLayoutAttribute.Height)
        
        
        footView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: pictureView, size: CGSize(width: UIScreen.mainScreen().bounds.size.width, height: 44), offset: CGPoint(x: -8, y: 10))
        
        contentView.addConstraint(NSLayoutConstraint(item: contentView, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: footView, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 8))
        
//        
//        footView.ff_AlignInner(type: ff_AlignType.BottomLeft, referView: contentView, size: CGSize(width: UIScreen.mainScreen().bounds.size.width, height: 44), offset: CGPointZero)
//
        
    
    
    }
    
    
    //MARK: - 懒加载
    private lazy var headView: YCStatusCellHeadView = YCStatusCellHeadView()

    private lazy var footView: YCStatusCellFootView = YCStatusCellFootView()
   
    private lazy var contentLab: UILabel = {
    
        let lab = UILabel(fontSize: 15, textColor: UIColor.blackColor())
        lab.numberOfLines = 0
        return lab
    
    }()
    
    //配图
    private lazy var pictureView: YCPictureView = YCPictureView()
    
    
}
